'''
Created on Jul 28, 2011

@author: mark
'''
from data import get_cursor

class Runner(object):
    '''
    classdocs
    '''
    

    def __init__(self, name, id=None):
        '''
        Constructor
        '''
        self.name = name
        if id is None:
            curs = get_cursor()
            curs.execute("INSERT INTO runners(name) values('%s')" 
                          % (self.name))
            curs.connection.commit()
            curs.execute('SELECT LAST_INSERT_ID()')
            self.id = curs.fetchone()[0]
            curs.close()
            
            
    def __str__(self):
        return '%s (%d)' %(self.name, self.id)
            
    def save(self):
        curs = get_cursor()
        curs.execute("UPDATE runners SET name = '%s' WHERE id = %d" % (self.name, self.id))
        curs.connection.commit()
        curs.close()